import { LAYER_CHANGE_TYPE } from "../common/GameConfig";
import LayerStatic from "../common/LayerStatic";
import PanelBase from "../common/PanelBase";
import EventManager from "../core/event/EventManager";
import { Event_Name } from "../core/event/event_mgr";


const { ccclass, property } = cc._decorator;

@ccclass
export default class RankItem extends PanelBase {

    // @property
    // text: string = 'hello';
    /** 排名 */
    @property(cc.Label) ranking: cc.Label = null;
    /** 头像 */
    @property(cc.Sprite) avatar: cc.Sprite = null;
    /** 昵称 */
    @property(cc.Label) nickname: cc.Label = null;
    /** 昵称 */
    @property(cc.Label) gameLevel: cc.Label = null;
    /** 昵称 */
    @property(cc.Label) gameNum: cc.Label = null;




    onLoad() {

    }



    start() {

    }

    setAll(data, index) {
        this.ranking.string = index + 1;
        this.sprite(data.head, this.avatar);
        this.nickname.string = data.nickname;
        this.gameLevel.string = data.game_level;
        this.gameNum.string = data.game_num;
    }


    sprite(avatar: string, head: cc.Sprite) {

        if (!avatar) avatar = "https://thirdwx.qlogo.cn/mmopen/vi_32/4MwaJwuQl7orrLGWacxPBw3VLJUcGad8QHYiaZ5NE3LhrvIVzDRF7AJuVXtlSCtEx79Jbjibe4OlvibTUgoEk9MKA/132"

        if (avatar && avatar.length > 0) {
            cc.assetManager.loadRemote(avatar, { ext: '.jpg' }, (err, pic: cc.Texture2D) => {
                if (err || !pic) { console.log("err", err); return; }
                let frame = new cc.SpriteFrame(pic);
                if (head.node && frame.isValid) head.spriteFrame = frame;
            })
        }
    }



    // update (dt) {}
}
